<script type="text/javascript" src="<?php echo $this->lib_base . "/" . 'mobile/goodsinfo.js'; ?>" charset="utf-8"></script>
<script type="text/javascript">
//<!CDATA[
/* buy */
function buy()
{
    if (goodsspec.getSpec() == null)
    {
        alert(lang.select_specs);
        return;
    }
    var spec_id = goodsspec.getSpec().id;

    var quantity = $("#quantity").val();
    if (quantity == '')
    {
        alert(lang.input_quantity);
        return;
    }
    if (parseInt(quantity) < 1 || isNaN(quantity))
    {
        alert(lang.invalid_quantity);
        return;
    }

    add_to_cart(spec_id, quantity);
}

/* add cart */
function add_to_cart(spec_id, quantity)
{
    var url = REAL_SITE_URL + '/index.php?app=cart&act=add';
    $.getJSON(url, {'spec_id':spec_id, 'quantity':quantity}, function(data){
    if (data.done)
    {
		$('.after_add_cart').show();
    }
    else
    {
       alert(data.msg);
    }
    })
}
/*buy_now*/
function buy_now()
{
    //验证数据
	if (goodsspec.getSpec() == null)
    {
        alert(lang.select_specs);
        return;
    }
    var spec_id = goodsspec.getSpec().id;
 
    var quantity = $("#quantity").val();
    if (quantity == '')
    {
        alert(lang.input_quantity);
        return;
    }
    if (parseInt(quantity) < 1 || isNaN(quantity))
    {
        alert(lang.invalid_quantity);
        return;
    }
    buy_now_add_cart(spec_id, quantity);
}

/* add buy_now_add_cart */
function buy_now_add_cart(spec_id, quantity)
{
    var url = REAL_SITE_URL + '/index.php?app=cart&act=add';
    $.getJSON(url, {'spec_id':spec_id, 'quantity':quantity}, function(data){
		if (data.done)
        {
			location.href= REAL_SITE_URL + '/index.php?app=order&goods=cart&store_id=<?php echo $this->_var['goods']['store_id']; ?>';
        }else{
            alert(data.msg);
        }
    });
}
var specs = new Array();
<?php $_from = $this->_var['goods']['_specs']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'spec');if (count($_from)):
    foreach ($_from AS $this->_var['spec']):
?>
specs.push(new spec(<?php echo $this->_var['spec']['spec_id']; ?>, '<?php echo htmlspecialchars($this->_var['spec']['spec_1']); ?>', '<?php echo htmlspecialchars($this->_var['spec']['spec_2']); ?>', <?php echo $this->_var['spec']['price']; ?>, <?php echo $this->_var['spec']['stock']; ?>));
<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
var specQty = <?php echo $this->_var['goods']['spec_qty']; ?>;
var defSpec = <?php echo htmlspecialchars($this->_var['goods']['default_spec']); ?>;
var goodsspec = new goodsspec(specs, specQty, defSpec);
//]]>
</script>
<div class="goods-detail">
	<div class="col-img">
    	<div class="scroll-wrapper">
		<div id="slides" class="scroller" >
			<?php $_from = $this->_var['goods']['_images']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'goods_image');$this->_foreach['fe_goods_image'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['fe_goods_image']['total'] > 0):
    foreach ($_from AS $this->_var['goods_image']):
        $this->_foreach['fe_goods_image']['iteration']++;
?>
			<div><img src="<?php echo $this->_var['site_url']; ?>/<?php echo $this->_var['goods_image']['thumbnail']; ?>" /></div>
        	<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>    
		</div>
		<ul class="new-banner-num new-tbl-type" id="idNum"></ul>
	</div>
    </div>
    <script>
    $(function() {
	 if($('#slides').children('div').length>1){
      	$('#slides').slidesjs({
        	width: 300,
        	height: 300,
			navigation: false,
			play: {
          	auto: false
        	}
      	});
	 }
	 	$('.handle .selected').click(function(){
		 	$(this).parent().find('.J_hidden').toggle();
			var cl = $(this).find('span').attr('class');
			if(cl == 'icon-arr')
			{
				$(this).find('span').attr('class','icon-arr-on');
			}
			else
			{
				$(this).find('span').attr('class','icon-arr');
			}
		})
		$('.change-quality em').click(function(){
			var type = $(this).attr('class');
			var _v = Number($('#quantity').val());
			var stock = Number($('*[ectype="goods_stock"]').text());
			if(type == 'plus')
			{
				if(_v > 1)
				{
					$('#quantity').val(_v-1);
				}
			}
			else if(_v < stock) {
				$('#quantity').val(_v+1);
			}else{
				alert('没有足够的商品。');
			}
		});
		
		$('.change-quality #quantity').keyup(function(){
			var _v = Number($('#quantity').val());
			var stock = Number($('*[ectype="goods_stock"]').text());
			if(_v > stock){ 
				alert('没有足够的商品。');
				$(this).val(stock);
			}
			if(_v < 1 || isNaN(_v)) {
				alert(lang.invalid_quantity);
				$(this).val(1);
			}
		});
		
		$('#J_message_box').css('left',(document.body.clientWidth-290)/2);
	});
  </script>
    
    
 	<div class="col-price clearfix">
    	<span class="float-left ml10 yahei fw-normal"><?php echo price_format($this->_var['goods']['price']); ?></span>
        <span class="float-right mr10"><a onclick="collect_goods(<?php echo $this->_var['goods']['goods_id']; ?>);" class="collect"></a></span>
    </div>
    
    <div class="col-title">
    	<h3><a class="fw-normal" href="#goods-detail-page" data-transition="slide">查看商品详情</a><a class="icon-arr" href="#goods-detail-page" data-transition="slide"></a></h3>
        <div class="title">
        	<span><?php echo htmlspecialchars($this->_var['goods']['goods_name']); ?></span>
            <font class="red"><?php $_from = $this->_var['goods']['tags']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'tag');if (count($_from)):
    foreach ($_from AS $this->_var['tag']):
?><?php echo $this->_var['tag']; ?>&nbsp;&nbsp;&nbsp;<?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?></font>
        </div>
    </div>
    <div class="line-background"></div>
    <div class="handle">
    	
            <?php if ($this->_var['goods']['spec_qty'] > 0): ?>
            <ul class="clearfix w-full J_hidden mb5">
                <li class="handle_title"><?php echo htmlspecialchars($this->_var['goods']['spec_name_1']); ?>: </li>
            </ul>
            <?php endif; ?>
            <?php if ($this->_var['goods']['spec_qty'] > 1): ?>
            <ul class="clearfix w-full J_hidden mb5">
                <li class="handle_title"><?php echo htmlspecialchars($this->_var['goods']['spec_name_2']); ?>: </li>
            </ul>
            <?php endif; ?>
            <ul class="clearfix w-full mb5">
                <li class="handle_title mr5" style="vertical-align:middle;">数量: </li>
                <li class="change-quality">
                	<em class="plus"><b></b></em>
                    <input type="text" class="text width1" name="" id="quantity" value="1" />
                    <em class="add"><b></b></em>
                </li>
                <span style="display:none;" ectype="goods_stock"><?php echo $this->_var['goods']['_specs']['0']['stock']; ?></span>
            </ul>
            	<?php if ($this->_var['goods']['spec_qty'] > 0): ?>
            <ul style="display:block;" class="clearfix w-full relative selected">
                <li style="display:inline-block;width:70px;" class="handle_title mr5">您已选择: </li>
                <li style="display:inline-block;" class="aggregate" ectype="current_spec"></li>
                <span class="icon-arr"></span>
            </ul>
            <?php endif; ?>
        </div>
    <div class="line-background"></div>
    <div class="col-evaluation">
    	<div class="info">
        	<a href="<?php echo url('app=goods&act=comments&id=' . $this->_var['goods']['goods_id']. ''); ?>" class="comments clearfix">
            	<span class="text float-left">商品评论</span>
                <span class="text float-right">
                	<em><?php echo $this->_var['goods']['comments']; ?></em> 人评价
                </span>
            </a>
            <span class="icon-arr"></span>
        </div>
        <div class="tbl-type">
        	<span class="tbl-cell">
            	<a href="<?php echo url('app=goods&act=saleslog&id=' . $this->_var['goods']['goods_id']. ''); ?>" class="btn-good">
                	<span class="icon"></span>
                    销售记录            </a>
            </span>
            <span class="tbl-cell">
            	<span class="bar">|</span>
            </span>
            <span class="tbl-cell">
            	<a href="<?php echo url('app=goods&act=qa&id=' . $this->_var['goods']['goods_id']. ''); ?>" class="btn-ser">
                	<span class="icon"></span>
                    产品咨询
                </a>
            </span>
        </div>
    </div>
    <div class="enter-store">
    	<a href="<?php echo url('app=store&id=' . $this->_var['store']['store_id']. ''); ?>"><i></i>进入店铺</a>
    </div>
    <div class="interest">
    	<h3>猜你喜欢</h3>
    	<div class="content">
        	<?php $_from = $this->_var['interest_goods']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'each');if (count($_from)):
    foreach ($_from AS $this->_var['each']):
?>
            <li class="clearfix">
                <?php $_from = $this->_var['each']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'igoods');if (count($_from)):
    foreach ($_from AS $this->_var['igoods']):
?>
                <a href="<?php echo url('app=goods&id=' . $this->_var['igoods']['goods_id']. ''); ?>">
                    <dl>
                        <dt><span><img src="<?php echo $this->_var['igoods']['default_image']; ?>" /></span></dt>
                        <dd>
                        	<p class="name"><?php echo htmlspecialchars($this->_var['igoods']['goods_name']); ?></p>
                            <p class="price"><?php echo price_format($this->_var['igoods']['price']); ?></p>
                       </dd>
                    </dl>
                </a>
                <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
            </li>
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
    	</ul>
    </div>
</div>
</div>
<div class="after_add_cart">
	<div class="message-box" id="J_message_box">
        <div class="tips">
           <b>添加成功</b>
           <span>商品已成加入购物车！</span>
        </div>
		<div class="continus2buy">
        	<a href="javascript:;" onclick="$('.after_add_cart').hide();">再逛逛</a>
            <a href="<?php echo url('app=cart'); ?>">去购物车</a>
        </div>
	</div>
    <div class="masker"></div>
</div>